<?php

namespace App\Models\Operation;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ContentTemplate extends Model
{
    use SoftDeletes;

    public $table = 'content_templates';

    protected $dates = ['deleted_at'];

    public $fillable = [
        // 内容模板编号
        'template_no',
        // 内容模板名称
        'name',
        // 模板别名
        'alias',
        // 模板类型
        'content_template_type_id',
        // 描述
        'description',
        // 排序
        'listorder',
        // 模板風格ID
        'template_style_id',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'template_no'              => 'string',
        'name'                     => 'string',
        'alias'                    => 'string',
        'content_template_type_id' => 'integer',
        'description'              => 'string',
        'listorder'                => 'integer',
        'template_style_id'        => 'integer',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'template_no'              => 'required|max:100',
        'name'                     => 'required|max:100',
        'alias'                    => 'required|max:100',
        'content_template_type_id' => 'required',
        'listorder'                => 'required',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function contentTemplateType()
    {
        return $this->hasOne(\App\Models\Operation\ContentTemplateType::class, 'id', 'content_template_type_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     **/
    public function contentTemplateDetails()
    {
        return $this->hasMany(\App\Models\Operation\ContentTemplateDetails::class, 'id', 'content_template_id');
    }

    public function cols()
    {
        return $this->hasOne(\App\Models\Entity\Column\Column::class, 'content_template_id', 'id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function templateStyle()
    {
        return $this->hasOne(\App\Models\Operation\TemplateStyle::class, 'id', 'template_style_id');
    }
}
